package neuralmusic.brain;

import neuralmusic.brain.module.Brain;
import neuralmusic.brain.module.Connection;
import neuralmusic.brain.module.Module;
import neuralmusic.brain.module.Neuron;

public class Global {

	public static Brain brain;

	public static void traceConnection(String string, Connection connection) {
		
		
		
		System.out.println(string);
		
		
		
		System.out.println("Connection ID: " + brain.getConnectionId(connection));
		for (Module m : brain.getModules()) {
			for (Neuron n : m.getNeurons()) {
				for (Connection c : n.getOutCOnnections()) {
					if (c == connection) {
						System.out.println(" Output of a Neuron in Module : "
								+ m.getName());
					}
				}
			}
		}

		for (Connection c : brain.getInputs()) {
			if (c == connection) {
				System.out.println(" INPUT to BRAIN ");
			}
		}

		for (Connection c : brain.getOutputs()) {
			if (c == connection) {
				System.out.println(" OUTPUT to BRAIN  ");
			}
		}
		
		for (Module m : brain.getModules()) {
			for (Connection c : m.getInputs()) {
				if (c == connection) {
					System.out.println(" INPUT to Module : " + m.getName());
				}
			}

			for (Connection c : m.getOutputs()) {
				if (c == connection) {
					System.out.println(" OUTPUT to Module : " + m.getName());
				}
			}
		}

		traceNeuron(connection.getSource());
	}

	private static void traceNeuron(Neuron source) {
		System.out.println(" tracing neuron "+ source);
		for (Module m:brain.getModules()){
			for (Neuron n:m.getNeurons()) {
				if (n == source) System.out.println(" Source neuron in module: " + m.getName());
			}
		}
		
	}

}
